<?php

namespace app\api\controller;


class Weather extends ApiBase {
    public function index() {
        $query = input('get.');
        if (!empty($query['city'])) {
            $key        = config('weather.key');
            $weatherUrl = sprintf(config('weather.url'), $query['city'], $key);
            $result     = curl_get($weatherUrl);
            if (!$result) {
                return show(1, '天气获取失败');
            }
            $result = json_decode($result, true);
            if ($result['resultcode'] != 200) {
                return show(1, '天气获取失败');
            }
            return show(config('code.success'), '天气获取成功', $result['result']['today']);
        }
    }
}